ASP MagicFile Component

The MagicFile object allows you to manipulate files and directories from an Active Server Page. You can create directories, remove them, search for specific files, and copy files from one destination to another. Directories and files can be searched recursively or non-recursively, depending upon your needs.

Purchasing MagicFile Component

Evaluation of MagicFile Component

Support

Installation

Working with MagicFile

 

 

Evaluation of MagicFile Component
Click here to download 30 days evaluation copy of MagicFile Component.

Purchasing MagicFile Component

You can get MagicFile on-line or by phone from The Registration Network.

 

Also, you may order by sending check to: Dana Consulting Inc. (in the memo field specify MagicFile)
Send it to:
Dana Consulting Inc.
14936 CreditView Drive
Savage, MN 55378

Please, print, fill out and enclose Order Form located in OrderForm.html file

Support
With any questions and/or suggestions email to support@dana-net.com.

Installation

  1. Stop the web server.
  2. To register MagicFile component move the magicfile.dll into a subdirectory (like \winnt\system32 for NT). To register the component on the system change to the directory where you installed the DLL and type: regsvr32 magicfile.dll
  3. Run Register.exe program, which comes with a component. Leave the Key filed empty and make sure you have word Evaluation in the name field and have the right component chosen under Component pull-down menu. Click Register button. It will give you a message saying when your component expires.
  4. Restart the web server.

Working with MagicFile

Calling the MagicFile Object from an ASP page

To call the MagicFile Object from an Active Server Page, you will need to create the object using the following code:
Set MyObj=Server.CreateObject("MagicFile.Tricks")
Remember to enclose the code within <% %> brackets.

Create a new directory
The following example creates a new directory called "shazam"

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
MyObj.CreateNewDirectory("c:\shazam") %>

Retrieve all files with a specified mask
The following example searches for all PDF files in the wwwroot directory:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.FileScanRecursive("c:\inetpub\wwwroot", "*.pdf")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
Else
for i=1 to MyObj.FileList.Count
response.write(MyObj.FileList(i))
response.write("<br>")
next
end if
%>

You can perform the same search in a non-recursive manner by using the FileScanSimple method, as shown below:
<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.FileScanSimple("c:\inetpub\wwwroot", "*.pdf")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
Else
for i=1 to MyObj.FileList.Count
response.write(MyObj.FileList(i))
response.write("<br>")
next
end if%>

Get the count of a file type
The following example provides a count of the number of PDF files:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
If Not (MyObj.FileScanRecursive("c:\inetpub\wwwroot", "*.pdf")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
Else
response.write(MyObj.FileList.Count & "PDF FILES<br>")
End If%>

Scan a directory recursively
The following example searches an entire directory tree and outputs a list of subfolders:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.DirScanRecursive("c:\")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
else
for i=1 to MyObj.DirList.Count
response.write(MyObj.DirList(i))
response.write("<br>")
next
end if%>

Scan a directory non-recursively
The following example shows a non-recursive search of the c: drive:

<%
Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.DirScanSimple("c:\")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
else
for i=1 to MyObj.DirList.Count
response.write(MyObj.DirList(i))
response.write("<br>")
next
end if%>

Remove a directory from the directory list
The following example shows how to remove a directory's name from the directory list collection. Note that this method does not actually remove the directory from the drive, but simply removes the directory from the list.

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.DirScanSimple("c:\inetpub\wwwroot")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
else
'remove any directories beginning with an underscore from the list
response.write(MyObj.RemoveFromDirList("_"))
for i=1 to MyObj.DirList.Count
response.write(MyObj.DirList(i))
response.write("<br>")
next
end if%>

 

Remove a file from the file list
The following example shows how to remove a file's name from the file list collection. Note that this method does not actually remove the file from the drive, but simply removes the file from the list.

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Dim i
If Not (MyObj.FileScanRecursive("c:\inetpub\wwwroot", "*.pdf")) then
response.write("The following Error Occured: ")
response.write(MyObj.ErrorDesc)
else
'remove the file called manual.pdf from the list
response.write(MyObj.RemoveFromFileList("manual.pdf"))
for i=1 to MyObj.FileList.Count
response.write(MyObj.FileList(i))
response.write("<br>")
next
end if%>

 

Check to see if file exists
The following example checks to see if the file called hello.txt exists in the MyDocuments directory:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
If MyObj.IsExists("c:\MyDocuments\hello.txt") then
response.write("yes")
Else
response.write("no")
End If%>

Copy File
The following example copies the file c:\hello.txt (the source file) to c:\inetpub\wwwroot\hello.txt (the destination file).

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
Call MyObj.CopyFile("c:\inetpub\wwwroot\hello.txt", "c:\hello.txt") %>

Get Properties
The following example scans a directory recursively and returns a list of files along with their respective file properties, such as file size and file type

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
call myobj.FileScanRecursive("c:\inetpub\wwwroot\magicfile", "*.*")
response.write myobj.FileList.Count
for i=1 to myobj.FileList.Count
response.write(myobj.FileList(i))
myobj.GetProperties(myobj.FileList(i) & " ")
response.write(myobj.ThisItem.ItemSize & " ")
response.write(myobj.ThisItem.Attr & " ")
response.write("<br>")
next %>

Clear File List
The following example creates a file list, then clears it:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
call myobj.FileScanRecursive("c:\inetpub\wwwroot\", "*.*")
response.write myobj.FileList.Count
call myobj.CleanFileList
response.write ("<br>")
response.write myobj.FileList.Count%>

 

Clear Directory List
The following example creates a directory list, then clears it:

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
call myobj.DirScanSimple("c:\inetpub\wwwroot\")
response.write myobj.DirList.Count
call myobj.CleanDirList
response.write ("<br>")
response.write myobj.DirList.Count%>

Delete File or Files
The following example deletes file myfile.tmp from c:\temp

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
call myobj.DeleteFromDisk("c:\temp\myfile.tmp")%>

The following example deletes all tmp files in c:\temp

<%Set MyObj=Server.CreateObject("MagicFile.Tricks")
call myobj.DeleteFromDisk("c:\temp\*.tmp")%>

Properties

Methods

 

Figure 1. Object Browser View of MagicFile